package cn.tedu.oop;

import java.util.Arrays;

/*本类用于实现宠物商店设计案例*/
public class TestAnimalShop {
    public static void main(String[] args) {
        //开始测试
        //创建宠物商店对象
        AnimalShop shop =new AnimalShop();
        //给宠物商店起名字
        shop.shopName = "爱宠宠物店";
        //查询宠物商店现在所有的宠物
        System.out.println(Arrays.toString(shop.animals));

        //创建动物对象--叫小白的3岁的小猫
        Cat cat = new Cat();
        cat.name = "小白";
        cat.age = 3;
        //将创建好的小猫对象存入animal[]中
        shop.animals[0] = cat;
        Cat cat1 = new Cat();
        cat1.name = "罗小黑";
        cat1.age = 5;
        shop.animals[1] = cat1;

        Dog dog = new Dog();
        dog.name = "旺柴";
        dog.age = 4;
        shop.animals[2] = dog;

        Bird bird = new Bird();
        bird.name ="银子";
        bird.age = 500;
        shop.animals[3] = bird;

        Dog dog1 = new Dog();
        dog1.name = "大米";
        dog1.age = 7 ;
        shop.animals[4] = dog1;

        //调用数组中不同小动物的功能
        shop.animals[0].eat();
        shop.animals[4].eat();


        //遍历数组
        for (int i = 0; i <5 ; i++) {
            System.out.println(shop.animals[i].name+shop.animals[i].age);
        }

        Animal a = shop.query(4);
        System.out.println(a.name+a.age);

        shop.buy(cat1);
        shop.buy(bird);
    }
}
//创建动物类的父类
class Animal{
    //定义动物类的属性
    public String name;
    public int age;
    //定义动物类的方法
    public void eat(){
        System.out.println("小动物Animal吃啥都行~");
    }
}
//创建子类小猫类
class Cat extends Animal{
    //继承后重写父类的方法
    @Override
    public void eat() {
        System.out.println("小猫爱吃小鱼干");
    }
    public void MiaoMiao(){
        System.out.println("小猫喜欢喵喵叫");
    }
}
//创建子类小鸟类
class Bird extends  Animal{}
//创建子类小狗类
class Dog extends  Animal{}
//创建宠物商店类
class AnimalShop{
    //定义属性
    public String shopName;//商店名
    //准备一个Animal类型的数组,用来存放小动物对象,长度为5
    public Animal[] animals = new Animal[5];

  //定义宠物商店的功能1--查询小动物
    public Animal query(int i){
        //传入下标,也就是数组下标,代表小动物的编号,返回数组中对应的小动物对象
        return animals[i];
    }
    //定义宠物商店的功能2--购买小动物
    public void buy(Animal animal){
        System.out.println("恭喜您要带:"+animal.name+"回家啦~");
        System.out.println("它"+animal.age+"岁啦,你要好好照顾它哦~");
    }
}